<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			//推送
			//#ifdef APP-PLUS 


			//plus.push.createMessage('你已经打开了app');

			plus.globalEvent.addEventListener('netchange', function() {
				console.log('----------------网络发生变化----------')
			});

			var info = plus.push.getClientInfo();
			console.log(JSON.stringify(info));
			if (info.clientid) {
				uni.setStorageSync('clientid', info.clientid)
			}

			/* 5+  push 消息推送 ps:使用:H5+的方式监听，实现推送*/
			plus.push.addEventListener("click", function(msg) {
				
				console.log("click:" + JSON.stringify(msg));
				console.log('------------msg.payload------------------')
				console.log(msg.payload);
				console.log(JSON.stringify(msg));

				var pages = getCurrentPages();
				var page = pages[pages.length - 1];
				console.log(pages.length)
				console.log('--------当前页面名称-------------');
				let payload;
				if(msg.aps){
					payload = JSON.parse(msg.aps.category)
				}else{
					payload = JSON.parse(msg.payload)
				}
					
				
				if (payload.type == 'test') {
					if (pages.length == 0) {
						uni.navigateTo({
							url: 'pages/index/test1?param=bai'
						})
					} else {
						uni.navigateTo({
							url: 'test1?param=bai'
						})
					}
				}

			}, false);
			// 监听在线消息事件    
			plus.push.addEventListener("receive", function(msg) {
				// plus.ui.alert(2);  
				//这里可以写跳转业务代码
				console.log("recevice:" + JSON.stringify(msg))
				let payload = msg.payload;
				console.log(payload)
				
				var options = {cover:false};    
				
				if(msg.type=='receive'){
					plus.push.createMessage(payload.content, JSON.stringify(payload), options);
				}
				
				
				
			}, false);

			//#endif 
		},
		onShow: function() {
			console.log('App Show')

		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
